package com.wu.llpsw.data;

import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodData;

public class playerData {
    //获取玩家攻击力
    public static double getAttack(Player player){
        if(player!=null) {
            AttributeInstance attack=player.getAttribute(Attributes.ATTACK_DAMAGE);
            return attack.getValue();
        }
        return -1.000d;
    }
    //修改玩家的攻击力
    public static void setAttack(Player player,double value){
        if(player!=null) {
            AttributeInstance attack=player.getAttribute(Attributes.ATTACK_DAMAGE);
            attack.setBaseValue(value);
        }
    }

    //获取玩家最大生命值
    public static double getMaxHealth(Player player){
        if(player!=null) {
            //ModifiableAttributeInstance health=player.getAttribute(Attributes.MAX_HEALTH);
            //return health.getValue();
            return player.getMaxHealth();
        }
        return -1.000d;
    }
    //修改玩家的最大生命值
    public static void setMaxtHealth(Player player,double value){
        if(player!=null) {
            AttributeInstance health=player.getAttribute(Attributes.MAX_HEALTH);
            health.setBaseValue(value);
        }
    }
    //获取玩家生命值
    public static double getHealth(Player player){
        if(player!=null) {
            return player.getHealth();
        }
        return -1.000d;
    }
    //修改玩家的生命值
    public static void setHealth(Player player,float value){
        if(player!=null) {
            player.setHealth(value);
        }
    }

    //设置玩家的护甲值
    public static void setFangyu(Player player,float value){
        AttributeInstance hujia=player.getAttribute(Attributes.ARMOR);
        AttributeInstance renxing=player.getAttribute(Attributes.ARMOR_TOUGHNESS);
        hujia.setBaseValue(value%30);
        renxing.setBaseValue(20.00d);
    }


    //获取玩家的护甲值
    public static double getFangyu(Player player){
        AttributeInstance hujia=player.getAttribute(Attributes.ARMOR);
        return hujia.getValue();
    }

    //获取玩家的等级
    public static int getLevel(Player player){
        return player.experienceLevel;
    }


    //获取玩家的当前饱食度
    public static float getNowBaoshi(Player player){
        FoodData foodStats = player.getFoodData();
        return foodStats.getSaturationLevel();
    }

    //修改玩家当前饱食度
    public static boolean setNowBaoshi(Player player,float value){
        FoodData foodStats = player.getFoodData();
        if (getNowBaoshi(player)+value>=0){
            foodStats.setSaturation(getNowBaoshi(player)+value);
            //player.getPersistentData();
            return true;
        }
        return false;
    }

    //修改玩家最大饱食度
    public static boolean setMaxBaoshi(Player player,int value){
        FoodData foodStats = player.getFoodData();
        if (getMazBaoshi(player)+value>=0){
            foodStats.setFoodLevel(value);
            return true;
        }
        return false;
    }
    //获取玩家最大饱食度
    public static float getMazBaoshi(Player player){
        FoodData foodStats = player.getFoodData();
        return foodStats.getFoodLevel();
    }
}
